<?php
class DivineservicesController extends AppController {

    public $helpers = array('Html', 'Form');
    public $components = array('Session');

    public function index() {
        $pageTitle ="Worldwide Seventhday-Adventisth Church - Kwabrafoso: Divine Service Programme";
        $in_record_data = $this->Divineservice->find('all');
        $this->set(compact('in_record_data','pageTitle'));
    }
  
    public function add(){
    $pageTitle ="Worldwide Seventh-day Adventist Church - Kwabrafoso: Enter Divine Service Programme";
     if($_POST){
       // pr($_POST);
        $data['Divineservice'] = array(
            'pyr' => $_POST['pyr'],
            'qtr' => $_POST['qtr'],
            'pdate' => $_POST['pdate'],
            'sec' => $_POST['sec'],
            'top' => $_POST['top'],
            'ser' => $_POST['ser'],
            'scr' => $_POST['scr'],
            'pry' => $_POST['pry'],
            'ket' => $_POST['ket'],
            'oph' => $_POST['oph'],
            'meh' => $_POST['meh'],
            'title' => $_POST['title'],
            'clh' => $_POST['clh']
        );

        if(!$this->Divineservice->save($data)){
            $this->Session->setFlash('Error Saving Divine Service Programme');
        }else{
             $this->Session->setFlash('Divine Service Programme Saved');
            $this->redirect('index');
        }
    }

    $this->set(compact('pageTitle','errorMsg'));
}
    
    // A functin to delete Divine Service Programme
    public function delete($id = null)
    {
       if (!$id) 
       {
        $this->Session->setFlash('Invalid id for Divine Service Programme');
        $this->redirect(array('action' => 'index'));
    }
    if ($this->Divineservice->delete($id)) 
    {
        $this->Session->setFlash('Divine Service Programme Deleted Please');
    } else 
    {
        $this->Session->setFlash(__('Divine Service Programme Not Deleted', true));
    }
    $this->redirect(array('action' => 'index'));
}

    // A functin to edit Divine Service Programme
    function edit($id = null){
    $record_id = $id;
    $conditions = array('Divineservice.id' => $record_id);
    $record = $this->Divineservice->find('first', array('conditions' => $conditions, 'recursive' => 1));
   // pr($record);
            
     $pageTitle ="Worldwide Seventh-day Adventist Church - Kwabrafoso: Edit Divine Service Programme";
     if($_POST){
        //pr($_POST);
        $data['Divineservice'] = array(
            'pyr' => $_POST['pyr'],
            'qtr' => $_POST['qtr'],
            'pdate' => $_POST['pdate'],
            'sec' => $_POST['sec'],
            'top' => $_POST['top'],
            'ser' => $_POST['ser'],
            'scr' => $_POST['scr'],
            'pry' => $_POST['pry'],
            'ket' => $_POST['ket'],
            'oph' => $_POST['oph'],
            'meh' => $_POST['meh'],
            'title' => $_POST['title'],
            'clh' => $_POST['clh']
        );

        if(!$this->Divineservice->save($data)){
            $this->Session->setFlash('Error Saving Data');
        }else{
             $this->Session->setFlash('Data Saved');
            $this->redirect('index');
        }
    }

    $this->set(compact('pageTitle','record'));
}

     // A functin to view Records
    public function view($id) {
    if (!$id) {
        throw new NotFoundException(__('Invalid Record'));
    }

    $divineservice = $this->Divineservice->findById($id);
    if (!$divineservice) {
        throw new NotFoundException(__('Invalid Record'));
    }
    $this->set('divineservice', $divineservice);
}

function report($id = null){
    $record_id = $id;
    $conditions = array('Divineservice.id' => $record_id);
    $record = $this->Divineservice->find('first', array('conditions' => $conditions, 'recursive' => 1));
//    pr($record);

}

}
?>
